package mblog.core.persist.dao.impl;

import mblog.core.persist.dao.ResourceAttachDao;
import mblog.core.persist.entity.ResourceAttachPO;
import mtons.modules.annotation.Repository;
import mtons.modules.persist.impl.BaseRepositoryImpl;
import org.hibernate.Query;

import java.util.List;

@Repository(entity = ResourceAttachPO.class)
public class ResourceAttachDaoImpl extends BaseRepositoryImpl<ResourceAttachPO> implements ResourceAttachDao {
    @Override
    public void deleteByPostId(long postId) {
        String hql = "delete from ResourceAttachPO where postId=:postId";
        Query query = createQuery(hql);
        query.setParameter("postId", postId);
        query.executeUpdate();
    }

    @Override
    public List<ResourceAttachPO> findByPostId(long postId) {
        String hql = "from ResourceAttachPO where postId=:postId";
        Query query = createQuery(hql);
        query.setParameter("postId", postId);
        return query.list();
    }
}
